package a66weding.com.jiehuntong.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.beans.CommonResultBean;
import a66weding.com.jiehuntong.beans.ErrorBean;
import a66weding.com.jiehuntong.beans.HttpRequestBean;
import a66weding.com.jiehuntong.beans.Modify_Status;
import a66weding.com.jiehuntong.beans.SuccessBean;
import a66weding.com.jiehuntong.common.MessageEvent;
import a66weding.com.jiehuntong.common.utils.CUtils;
import a66weding.com.jiehuntong.http.HttpHandleUtil;
import a66weding.com.jiehuntong.http.OnNetResultListener;
import a66weding.com.jiehuntong.http.RequestCode;
import a66weding.com.jiehuntong.http.UrlDealUtil;

/**
 * Created by admin on 2016/7/12.
 */
public class LocalActivity extends Activity implements View.OnClickListener,OnNetResultListener{
    private TextView saveTv;
    private EditText editText;
    //输入的地址内容;
    private String content;
    //该页的名字
    private String title;
    private TextView title_tv;
    private TextView back_iamge;
    private String place;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.job_edit_pager_location);
        Intent intent = getIntent();
        title = intent.getStringExtra(JobDetail.TASK_FLAG);
        place = intent.getStringExtra("place");
        initView();
    }
    private  void  initView(){
        saveTv = (TextView) findViewById(R.id.laocal_place_save);
        editText = (EditText) findViewById(R.id.local_place_editext);
        title_tv = (TextView) findViewById(R.id.title_tv);
        title_tv.setText(title+"地点");
        saveTv.setOnClickListener(this);
        back_iamge = (TextView) findViewById(R.id.back_iamge);
        back_iamge.setText(title);
        editText.setText(place);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onClick(View v) {
        content = editText.getText().toString();
        switch (v.getId()){
            case R.id.laocal_place_save:
                if( content==null||content.equals("")){
                    CUtils.showToast("你还没有设置地点");
                }else{
                    //网络请求
                    getChangePlace();
                    MessageEvent event  = new MessageEvent();
                    event.setPlace(content);
                    EventBus.getDefault().post(event);
                    finish();
                }
                break;
        }
    }

    private  void  getChangePlace(){
        String userurl = UrlDealUtil.getRealUrl(RequestCode.UPDATE_PLACE );
        HashMap<String,String> paramsMap = new HashMap<>();
        paramsMap.put("BookPlace",content);
        paramsMap.put("BookTitle",title);
        HttpRequestBean httpRequestBean = new HttpRequestBean(RequestCode.POSTEQUEST, userurl, this, CommonResultBean.class, RequestCode.UPDATE_PLACE, paramsMap);
        HttpHandleUtil.executeCommonPost(this,httpRequestBean);
    }

    @Override
    public void onSucess(SuccessBean sucessbean){
        Object data = sucessbean.getData();
        if(data instanceof CommonResultBean){
            CommonResultBean bean= (CommonResultBean) data;
            switch (bean.getResCode()){
                case "0000":
                    //请求成功
                    CUtils.showToast("修改成功了");
                    break;
                case "0001":
                    break;
                case "0002":
                    break;
                case "0003":
                    break;
            }
        }
    }

    @Override
    public void onError(ErrorBean errorBean) {

    }

    public void back(View view){
        finish();
    }

}
